//
//  PhotoScrollView.m
//  HWSGW
//
//  Created by avachen on 15/11/6.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"

@implementation PhotoScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _imgView = [[UIImageView alloc] initWithFrame:self.bounds];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self addSubview:_imgView];
        
        //1、设置缩放的最大、最小倍数
        self.maximumZoomScale = 3.0;
        self.minimumZoomScale = 1.0;
        
        //2、隐藏滚动条
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        //3、设置代理
        self.delegate = self;
        /*
         UIPanGestureRecognizer
          //轻扫
         UIPinchGestureRecognizer
         //捏合
         UILongPressGestureRecognizer
         //长按
         */
        //4、创建双击手势对象
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2:)];
        //设置点击数量
        tap2.numberOfTapsRequired = 2;
        //设置触摸手指的数量
//        tap.numberOfTouchesRequired = 2;
        
        [self addGestureRecognizer:tap2];
        //创建单机手势，用于隐藏显示导航栏
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
        [self addGestureRecognizer:tap];
        //当tap2手势被触发时，让tap手势失效
        [tap requireGestureRecognizerToFail:tap2];
        
        
    }
    return self;
}
- (void)tap:(UIGestureRecognizer *)tap{
//    NSLog(@"单击");
    [[NSNotificationCenter defaultCenter] postNotificationName:KClickNotification object:nil];
    
}
- (void)tap2:(UITapGestureRecognizer *)tap2{
//    NSLog(@"点击了1次");
    if (self.zoomScale > 1) {
//        self.zoomScale = 1;
        [self setZoomScale:1 animated:YES];
        
    }else{
//        self.zoomScale = 3;
        [self setZoomScale:3 animated:YES];
        
        
    }
}
//返回缩放子视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _imgView;
}
- (void)setUrl:(NSURL *)url
{
    if (_url != url) {
        _url = url;
        
        //加载图片
        [_imgView sd_setImageWithURL:url];
        
    }
}
@end
